﻿namespace MiniJob.Worker.Jobs;

/// <summary>
/// 处理器上下文
/// </summary>
public class JobContext
{
    public long JobId { get; set; }

    public long InstanceId { get; set; }

    public required string JobTypeName { get; set; }

    public required string JobFullName { get; set; }

    public string? JobParams { get; set; }

    public string? InstanceParams { get; set; }

    public int MaxTryCount { get; set; }

    public int TryCount { get; set; }

    /// <summary>
    /// 获取参数，优先获取实例参数，不存在则获取任务参数
    /// </summary>
    /// <returns></returns>
    public virtual string? GetParams()
    {
        if (!string.IsNullOrWhiteSpace(InstanceParams))
            return InstanceParams;
        return JobParams;
    }

    public override string ToString()
    {
        return $"JobTypeName:{JobTypeName},JobId:{JobId},InstanceId:{InstanceId}";
    }
}
